package com.wf.ew.sell.controller;

import com.wf.ew.common.BaseController;
import com.wf.ew.common.JsonResult;
import com.wf.ew.common.PageResult;
import com.wf.ew.sell.model.EntryBill;
import com.wf.ew.sell.model.EntryBillSon;
import com.wf.ew.sell.model.SellSon;
import com.wf.ew.sell.service.EntryBillService;
import com.wf.ew.sell.service.EntryBillSonService;
import com.wf.ew.system.model.Dictionarydata;
import com.wf.ew.system.service.DictionarydataService;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.IOException;
import net.sf.json.JSONArray;

/**
 *
 * controller
 * @author : Doman
 * @date : 2019-11-24 00:09:56
 * @version ：1.0
 */

@Controller
@RequestMapping("/sell/entryBillSon")
public class EntryBillSonController extends BaseController {

	@Autowired
	private EntryBillSonService entryBillSonService;
	@Autowired
	private EntryBillService entryBillService;
	@Autowired
	private DictionarydataService dictionarydataService;

	/**
	 * 计算入库单总价
	 */
	@RequiresPermissions("entryBillSon:view")
	@RequestMapping(value = "/calcTotalPrice", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String calcTotalPrice(EntryBillSon entryBillSon){
		return entryBillSonService.calcTotalPrice(entryBillSon, getLoginUser())+"";
	}

	/**
	 * 页面
	 **/
	@RequiresPermissions("entryBillSon:view")
	@RequestMapping()
	public String entryBillSon(Model model, EntryBill entryBill) {
		if(entryBill!=null && !entryBill.getId().equals("")){
			model.addAttribute("entryBill",entryBillService.getById(entryBill));
		}
		model.addAttribute("entryStateList",dictionarydataService.list(new Dictionarydata("entry_state")));
		model.addAttribute("invoiceList",dictionarydataService.list(new Dictionarydata("sell_invoice")));
		return "sell/entryBillSon.html";
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("entryBillSon:view")
	@RequestMapping(value = "/list", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String list(PageResult<T> page, EntryBillSon entryBillSon){
		return entryBillSonService.list(page, entryBillSon,getLoginUser());
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("entryBillSon:view")
	@RequestMapping(value = "/ajaxList", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String ajaxList(EntryBillSon entryBillSon){
		return JSONArray.fromObject(entryBillSonService.list(entryBillSon,getLoginUser())).toString();
	}

	/**
	 * 新增
	 **/
	@RequiresPermissions("entryBillSon:add")
	@ResponseBody
	@RequestMapping("/add")
	public JsonResult add(Model model, EntryBillSon entryBillSon) {
		return entryBillSonService.add(entryBillSon, getLoginUser());
	}

	/**
	 * 修改
	 **/
	@RequiresPermissions("entryBillSon:update")
	@ResponseBody
	@RequestMapping("/update")
	public JsonResult update(Model model, EntryBillSon entryBillSon) {
		return entryBillSonService.update(entryBillSon, getLoginUser());
	}

	/**
	 * 批量删除
	 **/
	@RequiresPermissions("entryBillSon:delete")
	@RequestMapping("/delete")
	@ResponseBody
	public JsonResult delete(EntryBillSon entryBillSon ) {
		return entryBillSonService.delete(entryBillSon, getLoginUser());
	}

}
